//
//  mainTableViewController.m
//  homeworkForYC
//
//  Created by 苗钧豪 on 16/7/27.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "mainTableViewController.h"
#import "AllCar.h"
#import "AllCar2.h"
#import "AllCar3.h"
#import "CarTableViewCell.h"
#import "JHView.h"
#import "BtnTableViewCell.h"

@interface mainTableViewController ()
@property(nonatomic,strong)NSMutableArray *array;// 大数组
@property(nonatomic,strong)NSMutableArray *array2;// 大数组
@property(nonatomic,strong)NSMutableArray *array3;// 大数组
@end

@implementation mainTableViewController
// 解析数据
- (void)getData {
    NSString *filepath = [[NSBundle mainBundle]pathForResource:@"YiChe" ofType:@"plist"];
    NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:filepath];
    self.array = [NSMutableArray array];
    self.array2 = [NSMutableArray array];
    self.array3 = [NSMutableArray array];
    NSDictionary *dic = [dictionary objectForKey:@"data"];
    NSArray *arr = [dic objectForKey:@"cycleImage"];
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *Dic in arr) {
        AllCar *allcar = [[AllCar alloc]init];
            [allcar setValuesForKeysWithDictionary:Dic];
            [_array addObject:allcar];
        [array addObject:allcar.picCover];
    }
    NSArray *arr2 = [dic objectForKey:@"list"];
    for (NSDictionary *Dic2 in arr2) {
        AllCar2 *allcar = [[AllCar2 alloc]init];
        [allcar setValuesForKeysWithDictionary:Dic2];
        [_array2 addObject:allcar];
    }
    

    // Do any additional setup after loading the view, typically from a nib.
    UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 300)];
    scrollview.contentOffset = CGPointMake(0, 0);
    scrollview.contentSize = CGSizeMake(self.view.bounds.size.width * 3, 0);
    for (int i = 1; i < 5; i ++) {
        UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake((i - 1) * self.view.bounds.size.width, 0, self.view.bounds.size.width, 300)];
        NSURL *url = [[NSURL alloc]initWithString:array[i - 1]];
        NSData *data = [[NSData alloc]initWithContentsOfURL:url];
        imgview.image = [UIImage imageWithData:data];
        [scrollview addSubview:imgview];
    }
    self.tableView.tableHeaderView = scrollview;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    // 注册cell
    [self.tableView registerClass:[CarTableViewCell class] forCellReuseIdentifier:@"yiche"];
    [self.tableView registerClass:[BtnTableViewCell class] forCellReuseIdentifier:@"haha"];
    self.tableView.rowHeight = 90;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
// 分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}
// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.array2.count;
}

// 设置cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        BtnTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"haha" forIndexPath:indexPath];
        [cell.btn1 setBackgroundImage:[UIImage imageNamed:@"1"] forState:(UIControlStateNormal)];
        [cell.btn2 setBackgroundImage:[UIImage imageNamed:@"2"] forState:(UIControlStateNormal)];
        [cell.btn3 setBackgroundImage:[UIImage imageNamed:@"3"] forState:(UIControlStateNormal)];
        [cell.btn4 setBackgroundImage:[UIImage imageNamed:@"4"] forState:(UIControlStateNormal)];
        return cell;
        
    }
    else {

    CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"yiche" forIndexPath:indexPath];
    cell.allcar = self.array2[indexPath.row];
    // Configure the cell...
    
    return cell;
    }
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
